package com.yanxi.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yanxi.mapper.StudentMapper;
import com.yanxi.pojo.PageResult;
import com.yanxi.pojo.Student;
import com.yanxi.pojo.StudentQueryParam;
import com.yanxi.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    //分页查询班级学员
    @Override
    public PageResult<Student> pageStudent(StudentQueryParam studentQueryParam) {
        PageHelper.startPage(studentQueryParam.getPage(), studentQueryParam.getPageSize());
        List<Student> studentList = studentMapper.pageStudent(studentQueryParam);
        Page<Student> p = (Page<Student>) studentList;
        return new PageResult<Student>(p.getTotal(), p.getResult());
    }

    //新增学员
    @Override
    public void saveStudent(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.saveStudent(student);
    }

    //根据id查询学员
    @Override
    public Student findById(Integer id) {
        return studentMapper.findById(id);
    }

    //修改学员
    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.update(student);
    }

    //删除学员
    @Override
    public void delete(List<Integer> ids) {
        studentMapper.delete(ids);
    }

    //扣分处理
    @Override
    public void violation(Integer id, Short score) {
        studentMapper.violation(id, score);
    }


}
